package edu.lsnu.equipment_management_system.pojo.domain;

import java.util.List;

/**
 * 关于分页显示：
 * 		用于存储当前页分页的相关的数据
 * @author Administrator
 *
 */
public class PageBean<T> {
    private List<T> content; // 当前页的数据：需要
    private int firstPage; // 首页：不需要手动输入
    private int prePage; // 上一页：不需要手动输入
    private int nextPage; // 下一页 ：不需要手动输入
    private int totalPage; // 总页数：不需要手动输入
    private int currentPage; // 当前页：需要
    private int totalCount; // 总记录数：需要
    private int pageSize; // 每页显示记录数：需要
    public PageBean() {}
    public PageBean(List<T> content, int currentPage, int totalCount, int pageSize) {
        super();
        this.content = content;
        this.currentPage = currentPage;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
    }
    /**
     * getContent、setContent
     * 获取或者存放当前页的数据对象：list，Ibsn对象。
     */
    public List<T> getContent() {
        return content;
    }
    public void setContent(List<T> content) {
        this.content = content;
    }
    /**
     * getFirstPage
     * 得到首页
     */
    public int getFirstPage() {
        return 1;
    }
	/*
	public void setFirstPage(int firstPage) {
		this.firstPage = firstPage;
	}
	*/
    /**
     * getPrePage
     * 得到上一页：
     * 		如果当前页是首页，则上一页也是当前页
     * 		如果上一页不是首页，则当前页减一
     */
    public int getPrePage() {
        return this.getCurrentPage() == this.getFirstPage() ?
                this.getFirstPage() :
                this.getCurrentPage() - 1;
    }
	/*
	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}
	*/
    /**
     * getNextPage
     * 得到下一页：
     * 		如果当前页是末页，则下一页也是当前页
     * 		如果当前页不是末页，那么下一页则是当前页加一
     */
    public int getNextPage() {
        return this.getCurrentPage() == this.getTotalPage() ?
                this.getTotalPage() :
                this.getCurrentPage() + 1;
    }
	/*
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}
	*/
    /**
     * getTotalPage
     * 得到总页数：
     * 		如果总记录数%每一页的pageSize == 0，totalPage=totalCount/pageSize
     * 		如果总记录数%每一页的pageSize != 0，totalPage=totalCount/pageSize + 1
     */
    public int getTotalPage() {
        return this.getTotalCount() % this.getPageSize() == 0 ?
                this.getTotalCount() / this.getPageSize() :
                this.getTotalCount() / this.getPageSize() + 1;
    }
    /*
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
    */
    public int getCurrentPage() {
        return currentPage;
    }
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
    public int getTotalCount() {
        return totalCount;
    }
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
	/*
	@Override
	public String toString() {
		return "PageBean [content=" + content + ", firstPage=" + firstPage + ", prePage=" + prePage + ", nextPage="
				+ nextPage + ", totalPage=" + totalPage + ", currentPage=" + currentPage + ", totalCount=" + totalCount
				+ ", pageSize=" + pageSize + "]";
	}
	*/

}
